# Maintainer: Alexey Pavlov <alexpux@gmail.om>
# Contributor: Ray Donnelly <mingw.android@gmail.com>

_realname=httplib2
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=0.18.1
pkgrel=1
pkgdesc="Comprehensive HTTP client library, supporting many features (mingw-w64)"
arch=('any')
license=('MIT')
url="https://github.com/httplib2/httplib2"
depends=("${MINGW_PACKAGE_PREFIX}-python"
         "${MINGW_PACKAGE_PREFIX}-python-certifi"
         "${MINGW_PACKAGE_PREFIX}-ca-certificates")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
source=(${_realname}-${pkgver}.tar.gz::https://github.com/httplib2/httplib2/archive/v${pkgver}.tar.gz
        cert.patch)
sha256sums=('f2f35e29e99e8d9bb5921c17ede6ee10bd5bd971f2cd0b3aaaa20088754f89ba'
            '3503625ade773c17c9c44f4017aec634ff03db0073eb3ec11e6882a466d7aae6')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # Patch, ref FS#40179
  patch -p1 -i "${srcdir}/cert.patch"

  cd "${srcdir}"
  rm -rf "python-build-${CARCH}" | true
  cp -r "${_realname}-${pkgver}" "python-build-${CARCH}"
}

build() {
  cd "${srcdir}/python-build-${CARCH}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

package() {
  cd "${srcdir}/python-build-${CARCH}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
    ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX#\/} --root="${pkgdir}" --optimize=1

  install -Dm644 LICENSE \
    "${pkgdir}${MINGW_PREFIX}"/share/licenses/python-${_realname}/LICENSE
}
